package com.myapplication.ui.listfragment;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.myapplication.bean.ListBean;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by zitaojiang on 2016/10/6.
 */
public class Presenter_List implements Contract_List.Presenter{
    Handler handler=new Handler(Looper.myLooper());
    private Contract_List.Model mModle;
    private Contract_List.View mView;

    public Presenter_List(Contract_List.View view){
        this.mView=view;
        mModle=new Model_List();
    }
    //获取数据
    @Override
    public void GetData(Map<String, String> params) {
        mModle.getData(params, new Callback<ListBean>() {
            @Override
            public void onResponse(Call<ListBean> call, Response<ListBean> response) {
                ListBean listBean=response.body();
                final List<ListBean.DataBean> listBeanList=listBean.getData();
                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        mView.onGetDataSuccess(listBeanList);
                        Log.i("TAG", "run: "+listBeanList.size());
                    }
                });
            }

            @Override
            public void onFailure(Call<ListBean> call, Throwable t) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        mView.onGetDataFail("网络连接失败");
                    }
                });
            }
        });
    }
}
